home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\SOURCE\REG.C < prev    next >
C/C++ Source or Header  |  1994-12-28  |  3KB  |  158 lines

  1. /*
  2.  * Written By Douglas A. Lewis <dalewis@cs.Buffalo.EDU>
  3.  *
  4.  * This file is in the public domain.
  5.  */
  6.  
  7. #ifndef lint
  8. static    char    rcsid[] = "@(#)$Id: reg.c,v 2.3 1994/10/17 11:32:35 mrg Exp $";
  9. #endif
  10.  
  11. #include "irc.h"
  12.  
  13. #include "ircaux.h"
  14.  
  15. static    int    total_explicit;
  16.  
  17. #define RETURN_FALSE -1
  18. #define RETURN_TRUE count
  19.  
  20. u_char lower_tab[256] = 
  21. {
  22.   0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
  23.  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  24.  32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  25.  48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  26.  64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  27. 112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95,
  28.  96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  29. 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
  30. 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  31. 144,145,145,147,148,149,150,151,152,153,154,155,156,157,158,159,
  32. 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  33. 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  34. 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  35. 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  36. 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  37. 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
  38. };
  39.  
  40. #undef tolower        /* don't want previous version. */
  41. #define tolower(x) lower_tab[x]
  42.  
  43. int _wild_match(mask, string)
  44.      u_char *mask, *string;
  45. {
  46.   register u_char *m = mask, *n = string, *ma = NULL, *na = NULL, temp;
  47.   int just = 0;
  48.   u_char *pm = NULL, *pn = NULL;
  49.   int lp_c = 0, count = 0, last_count = 0;
  50.  
  51.   while(1)
  52.     {
  53.  
  54.       switch (*m)
  55.     {
  56.     case '*':
  57.       goto ultimate_lameness;
  58.       break;
  59.     case '%':
  60.       goto ultimate_lameness2;
  61.       break;
  62.     case '?':
  63.       m++;
  64.       if (!*n++) return RETURN_FALSE;
  65.       break;
  66.     case 0:
  67.       if (!*n)
  68.         return RETURN_TRUE;
  69.     case '\\':
  70.       if ((*m=='\\') && (m[1]=='*') || (m[1]=='?')) m++;
  71.     default:
  72.       if (tolower(*m) != tolower(*n))
  73.         return RETURN_FALSE;
  74.       else
  75.         {
  76.           count++;
  77.           m++;
  78.           n++;
  79.         }
  80.     }
  81.     }
  82.  
  83.   while(1)
  84.     {
  85.  
  86.       switch (*m)
  87.     {
  88.     case '*':
  89. ultimate_lameness:
  90.       ma = ++m;
  91.       na = n;
  92.       just = 1;
  93.       last_count = count;
  94.       break;
  95.     case '%':
  96. ultimate_lameness2:
  97.       pm = ++m;
  98.       pn = n;
  99.       lp_c = count;
  100.       if (*n == ' ') pm = NULL;
  101.       break;
  102.     case '?':
  103.       m++;
  104.       if (!*n++) return RETURN_FALSE;
  105.       break;
  106.     case 0:
  107.       if (!*n || just)
  108.         return RETURN_TRUE;
  109.     case '\\':
  110.       if ((*m=='\\') && (m[1]=='*') || (m[1]=='?')) m++;
  111.     default:
  112.       just = 0;
  113.       if (tolower(*m) != tolower(*n))
  114.         {
  115.           if (!*n) return RETURN_FALSE;
  116.           if (pm)
  117.         {
  118.           m = pm;
  119.           n = ++pn;
  120.           count = lp_c;
  121.           if (*n == ' ') pm = NULL;
  122.         }
  123.           else
  124.         if (ma)
  125.           {
  126.             m = ma;
  127.             n = ++na;
  128.             if (!*n) return RETURN_FALSE;
  129.             count = last_count;
  130.           }
  131.         else return RETURN_FALSE;
  132.         }
  133.       else
  134.         {
  135.           count++;
  136.           m++;
  137.           n++;
  138.         }
  139.     }
  140.     }
  141. }
  142.  
  143. int    match(pattern, string)
  144. char    *pattern, *string;
  145. {
  146. /* -1 on false >= 0 on true */
  147.   return ((_wild_match(pattern, string)>=0)?1:0);
  148. }
  149.  
  150. int    wild_match(pattern, str)
  151. char    *pattern,
  152.     *str;
  153. {
  154.  
  155. /* assuming a -1 return of false */
  156.     return _wild_match(pattern, str) + 1;
  157. }
  158.